package ;

import controler.LevelEditorControler;
import events.ResizeEvent;
import flash.events.Event;
import flash.events.MouseEvent;
import flash.Lib;
import graphic.RenderObject;
import graphic.RessourceManager;
import graphic.Scene;
import model.LevelEditorModel;
import view.LevelEditorView;
import flash.display.StageScaleMode;

/**
 * @author Damien Mabin
 */

class Main 
{
	static var m_RessourceManager 		: RessourceManager;
	
	static var m_LevelEditorView 		: LevelEditorView;
	static var m_LevelEditorModel		: LevelEditorModel;
	static var m_LevelEditorControler 	: LevelEditorControler;
	
	static function main() 
	{
		haxe.Log.trace = function(v,?pos) { untyped __global__["trace"](v); }
		m_RessourceManager = RessourceManager.GetInstance();
		m_RessourceManager.addEventListener(RessourceManagerEvent.INITIALISATION_COMPLETE, OnInitialisationComplete);
	}
	
	static function OnInitialisationComplete(_Evt:Event):Void
	{
		Lib.current.stage.scaleMode = StageScaleMode.NO_SCALE;
		m_LevelEditorModel = new LevelEditorModel();
		m_LevelEditorView = new LevelEditorView(m_LevelEditorModel);
		m_LevelEditorControler = new LevelEditorControler(m_LevelEditorModel, m_LevelEditorView);
		Lib.current.stage.addChild(m_LevelEditorView);
		
		// Listen for resize event
		Lib.current.stage.addEventListener(Event.RESIZE, OnResize);
		Lib.current.stage.addEventListener(Event.FULLSCREEN, OnResize);
		
		// Ask  the view to take the good resolution
		m_LevelEditorView.dispatchEvent(new ResizeEvent(1024, 768));
	}
	static function OnResize(f_Evt : Event) : Void
	{
		m_LevelEditorView.dispatchEvent(new ResizeEvent(Lib.current.stage.stageWidth, Lib.current.stage.stageHeight));
    }
}